﻿/**  版本信息模板在安装目录下，可自行修改。
* TJ_SellInfoByMonth.cs
*
* 功 能： N/A
* 类 名： TJ_SellInfoByMonth
*
* Ver    变更日期             负责人  变更内容
* ───────────────────────────────────
* V0.01  2015/1/15 10:26:15   N/A    初版
*
* Copyright (c) 2012 Maticsoft Corporation. All rights reserved.
*┌──────────────────────────────────┐
*│　此技术信息为本公司机密信息，未经本公司书面同意禁止向第三方披露．　│
*│　版权所有：动软卓越（北京）科技有限公司　　　　　　　　　　　　　　│
*└──────────────────────────────────┘
*/
using DBUtil;
using Function;
using Model;
using Model.Permission;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;

namespace DAL
{
	/// <summary>
	/// 数据访问类:TJ_SellInfoByMonth
	/// </summary>
	public partial class TJ_SellInfoByMonthDAL
	{
         DbHelperSQLP DbHelperSQL = new DbHelperSQLP(PubConstant.JHShop);
         public TJ_SellInfoByMonthDAL()
		{}
		#region  Method


		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(long id)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from TJ_SellInfoByMonth");
			strSql.Append(" where id="+id+" ");
			return DbHelperSQL.Exists(strSql.ToString());
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public long Add(TJ_SellInfoByMonth model)
		{
			StringBuilder strSql=new StringBuilder();
			StringBuilder strSql1=new StringBuilder();
			StringBuilder strSql2=new StringBuilder();
			if (model.ShopID != null)
			{
				strSql1.Append("ShopID,");
				strSql2.Append(""+model.ShopID+",");
			}
			if (model.StatMonth != null)
			{
				strSql1.Append("StatMonth,");
				strSql2.Append("'"+model.StatMonth+"',");
			}
			if (model.SellNum != null)
			{
				strSql1.Append("SellNum,");
				strSql2.Append(""+model.SellNum+",");
			}
			if (model.SellMoney != null)
			{
				strSql1.Append("SellMoney,");
				strSql2.Append(""+model.SellMoney+",");
			}
			if (model.SellInCome != null)
			{
				strSql1.Append("SellInCome,");
				strSql2.Append(""+model.SellInCome+",");
			}
			if (model.SellBackNum != null)
			{
				strSql1.Append("SellBackNum,");
				strSql2.Append(""+model.SellBackNum+",");
			}
			if (model.SellBackMoney != null)
			{
				strSql1.Append("SellBackMoney,");
				strSql2.Append(""+model.SellBackMoney+",");
			}
			if (model.SellPay != null)
			{
				strSql1.Append("SellPay,");
				strSql2.Append(""+model.SellPay+",");
			}
			if (model.LargeNum != null)
			{
				strSql1.Append("LargeNum,");
				strSql2.Append(""+model.LargeNum+",");
			}
			if (model.LargeMoney != null)
			{
				strSql1.Append("LargeMoney,");
				strSql2.Append(""+model.LargeMoney+",");
			}
			if (model.LargeInCome != null)
			{
				strSql1.Append("LargeInCome,");
				strSql2.Append(""+model.LargeInCome+",");
			}
			if (model.LargeBackOrderNum != null)
			{
				strSql1.Append("LargeBackOrderNum,");
				strSql2.Append(""+model.LargeBackOrderNum+",");
			}
			if (model.LargeBackOrderMoney != null)
			{
				strSql1.Append("LargeBackOrderMoney,");
				strSql2.Append(""+model.LargeBackOrderMoney+",");
			}
			if (model.LargePay != null)
			{
				strSql1.Append("LargePay,");
				strSql2.Append(""+model.LargePay+",");
			}
			if (model.SendNum != null)
			{
				strSql1.Append("SendNum,");
				strSql2.Append(""+model.SendNum+",");
			}
			if (model.SendMoney != null)
			{
				strSql1.Append("SendMoney,");
				strSql2.Append(""+model.SendMoney+",");
			}
			if (model.SendInCome != null)
			{
				strSql1.Append("SendInCome,");
				strSql2.Append(""+model.SendInCome+",");
			}
			if (model.SendBackNum != null)
			{
				strSql1.Append("SendBackNum,");
				strSql2.Append(""+model.SendBackNum+",");
			}
			if (model.SendBackMoney != null)
			{
				strSql1.Append("SendBackMoney,");
				strSql2.Append(""+model.SendBackMoney+",");
			}
			if (model.SendPay != null)
			{
				strSql1.Append("SendPay,");
				strSql2.Append(""+model.SendPay+",");
			}
			if (model.AllInCome != null)
			{
				strSql1.Append("AllInCome,");
				strSql2.Append(""+model.AllInCome+",");
			}
			if (model.AllPay != null)
			{
				strSql1.Append("AllPay,");
				strSql2.Append(""+model.AllPay+",");
			}
			if (model.Note != null)
			{
				strSql1.Append("Note,");
				strSql2.Append("'"+model.Note+"',");
			}
			strSql.Append("insert into TJ_SellInfoByMonth(");
			strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1));
			strSql.Append(")");
			strSql.Append(" values (");
			strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1));
			strSql.Append(")");
			strSql.Append(";select @@IDENTITY");
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt64(obj);
			}
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(TJ_SellInfoByMonth model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update TJ_SellInfoByMonth set ");
			if (model.ShopID != null)
			{
				strSql.Append("ShopID="+model.ShopID+",");
			}
			if (model.StatMonth != null)
			{
				strSql.Append("StatMonth='"+model.StatMonth+"',");
			}
			if (model.SellNum != null)
			{
				strSql.Append("SellNum="+model.SellNum+",");
			}
			if (model.SellMoney != null)
			{
				strSql.Append("SellMoney="+model.SellMoney+",");
			}
			if (model.SellInCome != null)
			{
				strSql.Append("SellInCome="+model.SellInCome+",");
			}
			if (model.SellBackNum != null)
			{
				strSql.Append("SellBackNum="+model.SellBackNum+",");
			}
			if (model.SellBackMoney != null)
			{
				strSql.Append("SellBackMoney="+model.SellBackMoney+",");
			}
			if (model.SellPay != null)
			{
				strSql.Append("SellPay="+model.SellPay+",");
			}
			if (model.LargeNum != null)
			{
				strSql.Append("LargeNum="+model.LargeNum+",");
			}
			if (model.LargeMoney != null)
			{
				strSql.Append("LargeMoney="+model.LargeMoney+",");
			}
			if (model.LargeInCome != null)
			{
				strSql.Append("LargeInCome="+model.LargeInCome+",");
			}
			if (model.LargeBackOrderNum != null)
			{
				strSql.Append("LargeBackOrderNum="+model.LargeBackOrderNum+",");
			}
			if (model.LargeBackOrderMoney != null)
			{
				strSql.Append("LargeBackOrderMoney="+model.LargeBackOrderMoney+",");
			}
			if (model.LargePay != null)
			{
				strSql.Append("LargePay="+model.LargePay+",");
			}
			if (model.SendNum != null)
			{
				strSql.Append("SendNum="+model.SendNum+",");
			}
			if (model.SendMoney != null)
			{
				strSql.Append("SendMoney="+model.SendMoney+",");
			}
			if (model.SendInCome != null)
			{
				strSql.Append("SendInCome="+model.SendInCome+",");
			}
			if (model.SendBackNum != null)
			{
				strSql.Append("SendBackNum="+model.SendBackNum+",");
			}
			if (model.SendBackMoney != null)
			{
				strSql.Append("SendBackMoney="+model.SendBackMoney+",");
			}
			if (model.SendPay != null)
			{
				strSql.Append("SendPay="+model.SendPay+",");
			}
			if (model.AllInCome != null)
			{
				strSql.Append("AllInCome="+model.AllInCome+",");
			}
			if (model.AllPay != null)
			{
				strSql.Append("AllPay="+model.AllPay+",");
			}
			if (model.Note != null)
			{
				strSql.Append("Note='"+model.Note+"',");
			}
			int n = strSql.ToString().LastIndexOf(",");
			strSql.Remove(n, 1);
			strSql.Append(" where id="+ model.id+"");
			int rowsAffected=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rowsAffected > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(long id)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from TJ_SellInfoByMonth ");
			strSql.Append(" where id="+id+"" );
			int rowsAffected=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rowsAffected > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string idlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from TJ_SellInfoByMonth ");
			strSql.Append(" where id in ("+idlist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public TJ_SellInfoByMonth GetModel(long id)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1  ");
			strSql.Append(" id,ShopID,StatMonth,SellNum,SellMoney,SellInCome,SellBackNum,SellBackMoney,SellPay,LargeNum,LargeMoney,LargeInCome,LargeBackOrderNum,LargeBackOrderMoney,LargePay,SendNum,SendMoney,SendInCome,SendBackNum,SendBackMoney,SendPay,AllInCome,AllPay,Note ");
			strSql.Append(" from TJ_SellInfoByMonth ");
			strSql.Append(" where id="+id+"" );
			TJ_SellInfoByMonth model=new TJ_SellInfoByMonth();
			DataSet ds=DbHelperSQL.Query(strSql.ToString());
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public TJ_SellInfoByMonth DataRowToModel(DataRow row)
		{
			TJ_SellInfoByMonth model=new TJ_SellInfoByMonth();
			if (row != null)
			{
				if(row["id"]!=null && row["id"].ToString()!="")
				{
					model.id=long.Parse(row["id"].ToString());
				}
				if(row["ShopID"]!=null && row["ShopID"].ToString()!="")
				{
					model.ShopID=int.Parse(row["ShopID"].ToString());
				}
				if(row["StatMonth"]!=null)
				{
					model.StatMonth=row["StatMonth"].ToString();
				}
				if(row["SellNum"]!=null && row["SellNum"].ToString()!="")
				{
					model.SellNum=int.Parse(row["SellNum"].ToString());
				}
				if(row["SellMoney"]!=null && row["SellMoney"].ToString()!="")
				{
					model.SellMoney=decimal.Parse(row["SellMoney"].ToString());
				}
				if(row["SellInCome"]!=null && row["SellInCome"].ToString()!="")
				{
					model.SellInCome=decimal.Parse(row["SellInCome"].ToString());
				}
				if(row["SellBackNum"]!=null && row["SellBackNum"].ToString()!="")
				{
					model.SellBackNum=int.Parse(row["SellBackNum"].ToString());
				}
				if(row["SellBackMoney"]!=null && row["SellBackMoney"].ToString()!="")
				{
					model.SellBackMoney=decimal.Parse(row["SellBackMoney"].ToString());
				}
				if(row["SellPay"]!=null && row["SellPay"].ToString()!="")
				{
					model.SellPay=decimal.Parse(row["SellPay"].ToString());
				}
				if(row["LargeNum"]!=null && row["LargeNum"].ToString()!="")
				{
					model.LargeNum=int.Parse(row["LargeNum"].ToString());
				}
				if(row["LargeMoney"]!=null && row["LargeMoney"].ToString()!="")
				{
					model.LargeMoney=decimal.Parse(row["LargeMoney"].ToString());
				}
				if(row["LargeInCome"]!=null && row["LargeInCome"].ToString()!="")
				{
					model.LargeInCome=decimal.Parse(row["LargeInCome"].ToString());
				}
				if(row["LargeBackOrderNum"]!=null && row["LargeBackOrderNum"].ToString()!="")
				{
					model.LargeBackOrderNum=int.Parse(row["LargeBackOrderNum"].ToString());
				}
				if(row["LargeBackOrderMoney"]!=null && row["LargeBackOrderMoney"].ToString()!="")
				{
					model.LargeBackOrderMoney=decimal.Parse(row["LargeBackOrderMoney"].ToString());
				}
				if(row["LargePay"]!=null && row["LargePay"].ToString()!="")
				{
					model.LargePay=decimal.Parse(row["LargePay"].ToString());
				}
				if(row["SendNum"]!=null && row["SendNum"].ToString()!="")
				{
					model.SendNum=int.Parse(row["SendNum"].ToString());
				}
				if(row["SendMoney"]!=null && row["SendMoney"].ToString()!="")
				{
					model.SendMoney=decimal.Parse(row["SendMoney"].ToString());
				}
				if(row["SendInCome"]!=null && row["SendInCome"].ToString()!="")
				{
					model.SendInCome=decimal.Parse(row["SendInCome"].ToString());
				}
				if(row["SendBackNum"]!=null && row["SendBackNum"].ToString()!="")
				{
					model.SendBackNum=int.Parse(row["SendBackNum"].ToString());
				}
				if(row["SendBackMoney"]!=null && row["SendBackMoney"].ToString()!="")
				{
					model.SendBackMoney=decimal.Parse(row["SendBackMoney"].ToString());
				}
				if(row["SendPay"]!=null && row["SendPay"].ToString()!="")
				{
					model.SendPay=decimal.Parse(row["SendPay"].ToString());
				}
				if(row["AllInCome"]!=null && row["AllInCome"].ToString()!="")
				{
					model.AllInCome=decimal.Parse(row["AllInCome"].ToString());
				}
				if(row["AllPay"]!=null && row["AllPay"].ToString()!="")
				{
					model.AllPay=decimal.Parse(row["AllPay"].ToString());
				}
				if(row["Note"]!=null)
				{
					model.Note=row["Note"].ToString();
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select id,ShopID,StatMonth,SellNum,SellMoney,SellInCome,SellBackNum,SellBackMoney,SellPay,LargeNum,LargeMoney,LargeInCome,LargeBackOrderNum,LargeBackOrderMoney,LargePay,SendNum,SendMoney,SendInCome,SendBackNum,SendBackMoney,SendPay,AllInCome,AllPay,Note ");
			strSql.Append(" FROM TJ_SellInfoByMonth ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" id,ShopID,StatMonth,SellNum,SellMoney,SellInCome,SellBackNum,SellBackMoney,SellPay,LargeNum,LargeMoney,LargeInCome,LargeBackOrderNum,LargeBackOrderMoney,LargePay,SendNum,SendMoney,SendInCome,SendBackNum,SendBackMoney,SendPay,AllInCome,AllPay,Note ");
			strSql.Append(" FROM TJ_SellInfoByMonth ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM TJ_SellInfoByMonth ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
            strSql.Append("SELECT SUM(TT.InCome) AS sy_value FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.id desc");
			}
			strSql.Append(")AS Row, T.*  from TJ_SellInfoByMonth T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		*/

		#endregion  Method
		#region  MethodEx

		#endregion  MethodEx
	}
}

